package EBM.BLL;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

public class Operation {
	private String cmd;
	private List<Object> response;
	private UserManage userMan;
	private ProjectManage projectMan;
	private BugManage bugManage;
	
	public List<Object> GetResponse(Object command, List<Object> request) 
	throws SQLException, ClassNotFoundException, ParseException{
		
		cmd = command.toString();
		if (cmd == null || cmd.length() == 0)
			return null;
		cmd = cmd.trim();
		//登陆
		if(cmd.equals("logon")){
			userMan = new UserManage();
			response = userMan.CheckUser(request);
		}
		//修改密码
		else if(cmd.equals("modifypwd")){
			userMan = new UserManage();
			response = userMan.ModifyPwd(request);
		}
		//添加用户
		else if(cmd.equals("adduser")){
			userMan = new UserManage();
			response = userMan.AddUsr(request);
		}
		//删除用户
		else if(cmd.equals("deleteuser")){
			userMan = new UserManage();
			response = userMan.DeleteUser(request);
		}
		//得到所有用户
		else if(cmd.equals("getalluser")){
			userMan = new UserManage();
			response = userMan.GetAllUser();
		}
		//查询用户列表
		else if(cmd.equals("queryuser")){
			userMan = new UserManage();
			response = userMan.FindUserList(request);
		}
		//修改用户信息
		else if(cmd.equals("fixuser")){
			userMan = new UserManage();
			response = userMan.FixUsr(request);
		}
		//得到所有项目
		else if(cmd.equals("getallproject")){
			projectMan = new ProjectManage();
			response = projectMan.GetAllProject();
		}
		//得到和某个用户相关的项目
		else if(cmd.equals("getprojectbyuserid")){
			projectMan = new ProjectManage();
			response = projectMan.GetProjectByUserid(request);
		}
		//得到某一项目的所有信息，包括模块和人员，以及其余的人员
		else if(cmd.equals("getprojectdetailinfo")){
			projectMan = new ProjectManage();
			response = projectMan.GetProjectDetailInfo(request);
		}
		//添加项目
		else if(cmd.equals("addproject")){
			projectMan = new ProjectManage();
			response = projectMan.AddProject(request);
		}
		//修改项目
		else if(cmd.equals("fixproject")){
			projectMan = new ProjectManage();
			response = projectMan.FixProject(request);
		}
		//添加项目的模块
		else if(cmd.equals("addprojectmodel")){
			projectMan = new ProjectManage();
			response = projectMan.AddProjectModel(request);
		}
		//删除项目的模块
		else if(cmd.equals("deleteprojectmodel")){
			projectMan = new ProjectManage();
			response = projectMan.DeleteProjectModel(request);
		}
		//添加项目的人员
		else if(cmd.equals("addprojectuser")){
			projectMan = new ProjectManage();
			response = projectMan.AddProjectUser(request);
		}
		//删除项目的人员
		else if(cmd.equals("deleteprojectuser")){
			projectMan = new ProjectManage();
			response = projectMan.DeleteProjectUser(request);
		}
		//创建缺陷: 保存、提交
		else if(cmd.equals("newbugsave")||cmd.equals("newbugsubmit")){
			bugManage = new BugManage();
			response = bugManage.newBug(cmd, request);
		}
		//提交草稿缺陷
		else if(cmd.equals("submitdraftbug")){
			String projectName = null;
			int bid = 0;
			try
			{
				projectName = request.get(0).toString();
				bid = Integer.parseInt(EBM.util.BugID.ConvertFromClientToServer(request.get(1).toString()));
			}
			catch(Exception ex)
			{
				response = new ArrayList<Object>();
				response.add(new String("-1"));
			}
			bugManage = new BugManage();
			System.out.print("submit: " + projectName + ", " + bid);
			response = bugManage.submitDraftBug(projectName, bid);
		}
		//审核缺陷
		else if(cmd.equals("checkbug")){
			bugManage = new BugManage();
			response = bugManage.checkBug(request);
		}
		//定位缺陷
		else if(cmd.equals("locatebug")){
			bugManage = new BugManage();
			response = bugManage.LocateBug(request);
		}
		//修改缺陷
		else if(cmd.equals("fixbug")){
			bugManage = new BugManage();
			response = bugManage.FixBug(request);
		}
		//验证缺陷
		else if(cmd.equals("verifybug")){
			bugManage = new BugManage();
			response = bugManage.VerifyBug(request);
		}
		//查询缺陷报告单列表,无条件
		else if(cmd.equals("getbugbyprojectidforreviewuser")){
			bugManage = new BugManage();
			response = bugManage.FindBugListByProid(request);
		}
		//查询缺陷报告单列表
		else if(cmd.equals("querybugreport")){
			bugManage = new BugManage();
			response = bugManage.FindBugList(request);
		}
		//查询缺陷报告单列表,用户是当前责任人
		else if(cmd.equals("getbugbyprojectid")){
			bugManage = new BugManage();
			response = bugManage.FindBugListByResponsibleUserid(request);
		}
		//查询缺陷报告单的详细信息 proid bugid
		else if(cmd.equals("getbugdetail")){
			bugManage = new BugManage();
			response = bugManage.FindBugDetailInfo(request);
		}
		//查询缺陷报告单的日志 proid bugid
		else if(cmd.equals("getbuglog")){
			bugManage = new BugManage();
			response = bugManage.FindBugLog(request);
		}
		return response;
	}
}
